﻿@using KRM.Core
@model IEnumerable<KRM.Core.tblCustomerHelpRequest>

@{
    ViewBag.Title = "Customer Help Request";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Scripts{
    <script src="~/js/customer.js"></script>
}
<div class="container-fluid" >
    <div class="box"style="margin-top: 20px">
        <div class="fieldset">
            <div class="legend"><span >Filter</span></div>
            <form id="frSearchCancelOrderRequest">
                <div class="row-fluid">
                    <div class="span4">
                        <div class="row-fluid">
                            <div class="span4">Type: </div>
                            <div class="span8">@Html.DropDownList("TypeId",null,new{@class="input-block-level", @onchange="$('#frSearchCancelOrderRequest').submit()"})</div>
                        </div>
                    </div>

                    <div class="span4">
                        <div class="row-fluid">
                            <div class="span4">Status: </div>
                            <div class="span8">@Html.DropDownList("StatusId",null,new{@class="input-block-level", @onchange="$('#frSearchCancelOrderRequest').submit()"})</div>
                        </div>
                    </div>

                    <div class="span4">
                        <div class="row-fluid">
                            <div class="span4">OrderRef:</div>
                            <div class="span8"><input type="text" class="input-block-level" name="OrderRef"id="OrderRef"/></div>
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span4">
                        <div class="row-fluid">
                            <div class="span4">From:</div>
                            <div class="span8">
                                <div id="datetimepicker2" class="input-append input-block-level">
                                    <input data-format="MM/dd/yyyy" type="text" name="dateFrom" placeholder="From" value="@(Request["dateFrom"]??DateTime.Now.AddDays(-7).ToString("MM/dd/yyyy"))"style="width: 79%">
                                    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                                    </span>
                                </div>
                            </div>
                        </div></div>
                    <div class="span4">
                        <div class="row-fluid">
                            <div class="span4">To:</div>
                            <div class="span8">
                                <div id="datetimepicker3" class="input-append input-block-level">
                                    <input data-format="MM/dd/yyyy" type="text" name="dateTo" placeholder="To" value="@(Request["dateTo"]??DateTime.Now.ToString("MM/dd/yyyy"))" style="width: 79%">
                                    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" class="icon-calendar"></i>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="span2">
                        <button type="submit" class="btn btn-primary">Search</button>
                        <a href="/Customer/CustomerHelpRequest" class="btn">Refresh</a>
                    </div>
                </div>
            </form>
    
        </div>
        <div class="fieldset"id="FilterResults">
            @*            <div id="ViewDetail" class="modal fade" tabindex="-1" data-width="900">
                <div style="height: 500px" >
                    <div style="height: 220px"></div>
                    <div class="ajax-loading"></div>
                </div>
            </div>*@
            <div class="legend" ><span >Filter Results</span></div>

            <table class="table table-bordered table-fix table-nohidden krmtable" data-height='450'>
                <a href="dsfsd"  target="_blank"  id="hrefBlank"></a>
                @if (ViewBag.SelectedStatusId==1)
                {
                    <thead id="tbPendingInvoiceOrderhead">
                        <tr>
                            <th>Action</th>
                            <th>OrderRef</th>
                            <th>Date Request</th>
                            <th>CustomerName</th>
                            <th>Email address</th>
                            <th>Telephone number</th> 
                            @switch ((int)ViewBag.SelectedTypeId)
                            {
                                case 1:
                                    <th>Damage Parts</th>
                                    <th>Attach photo link</th>
                                    break;
                                case 2:<th>Missing Parts</th>
                                    break;
                                case 3:<th>Has your order been received?</th>
                                    break;
                                case 4:<th>Reason to return</th><th>Item to return</th>
                                    break;
                                case 5:<th>Item Cancel</th><th>Reason for cancellation</th>
                                    break;
                                case 6:<th>Introduction</th><th>Product Categories</th><th>Contact Name</th>
                                    break;
                                case 7:<th>Introduction</th><th>Product Categories</th><th>Contact Name</th>
                                    break;
                            }
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            <tr>
                                <td>
                                    @Html.DropDownList("ActionId",null,new{@class="input-block-level",@Id="cbbActionId"+item.Id})
                                    <button type="button" class="btn btn-primary"  onclick="ApproveCancelOrderRequest(@item.Id,@item.TypeId,$('#cbbActionId@(@item.Id)').val(),'','@item.OrderRef','@item.OrderItemId')" aria-hidden="true">Approve</button>
                                    <button type="button" class="btn btn-danger"  onclick="DeclineCancelOrderRequest(@item.Id,$('#cbbActionId@(@item.Id)').val())" aria-hidden="true">Decline</button>
                                </td>
                                <td><a target="Blank" href="/orderview/orderdetail?OrderRef=@item.OrderRef">@item.OrderRef</a></td> 
                                <td>@(item.DateRequest==null?"":((DateTime)item.DateRequest).ToString("MM/dd/yyyy HH:mm:ss"))</td>
                                <td>@item.CustomerName</td>
                                <td>@item.EmailAddress</td> 
                                <td>@item.TelephoneNumber</td>
                                @switch ((int)ViewBag.SelectedTypeId)
                                {
                                    case 1:
                                        <td>@Html.Raw(string.Join("<br>",item.Parts.Select(p=>"<b>PartID:</b> "+p.PartId+" <b>Qty:</b>"+p.Quantity+" <b>Description:</b>"+p.PartDescription).ToList()))</td>
                                        <td>
                                            @if (!string.IsNullOrEmpty(item.AttachPhotoLink))
                                            {
                                                foreach (var photo in item.AttachPhotoLink.Split(';'))
                                                {
                                                    <a target="_blank" href="/rdm/getfile?path=@photo">@photo.Split('\\').Last()</a>
                                                @*<img src="/rdm/getfile?path=@photo" style="width: 80px; height: 60px"/>*@
                                                }
                                            }
                                        </td>
                                        break;
                                    case 2:
                                        <td>@Html.Raw(string.Join("<br>",item.Parts.Select(p=>"<b>PartID:</b> "+p.PartId+" <b>Qty:</b>"+p.Quantity+" <b>Description:</b>"+p.PartDescription).ToList()))</td>
                                        <td>@item.TelephoneNumber</td>
                                        break;
                                    case 3:<td>@item.OrderStatus</td>
                                        break;
                                    case 4:<td>@item.ReasonToReturn</td><td>@item.ItemToReturn</td>
                                        break;
                                    case 5:<td>@item.ProductName</td>
                                        <td>@item.ReasonForCancellation</td>
                                        break;
                                    case 6 :<td>@item.SupplierIntroduction</td><td>@item.SupplierProductCategories</td><td>@item.SupplierContactName</td>
                                        break;
                                    case 7:<td>@item.AffiliateIntroduction</td><td>@item.AffiliateProductCategories</td><td>@item.AffiliateContactName</td>
                                        break;
                                }
                                
                                
                                
                            </tr>
                        }
                    </tbody>
                }
                else
                {
                    <thead>
                        <tr>
                            <th>OrderRef</th>
                            <th>Date Request</th>
                            <th>CustomerName</th>
                            <th>Email address</th>
                            <th>Telephone number</th> 
                            @switch ((int)ViewBag.SelectedTypeId)
                            {
                                case 1:<th>Attach photo link</th>
                                    break;
                                case 2:
                                    break;
                                case 3:<th>Has your order been received?</th>
                                    break;
                                case 4:<th>Reason to return</th><th>Item to return</th>
                                    break;
                                case 5:<th>Item Cancel</th><th>Reason for cancellation</th>
                                    break;
                                case 6:<th>Introduction</th><th>Product Categories</th><th>Contact Name</th>
                                    break;
                                case 7:<th>Introduction</th><th>Product Categories</th><th>Contact Name</th>
                                    break;
                            }
                            <th>DateApproved</th>
                            <th>UserApproved</th>
                            <th>Action</th>
                            <th>Reason</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            <tr>
                                <td><a target="Blank" href="/orderview/orderdetail?OrderRef=@item.OrderRef">@item.OrderRef</a></td> 
                                <td>@(item.DateRequest==null?"":((DateTime)item.DateRequest).ToString("MM/dd/yyyy HH:mm:ss"))</td>
                                <td>@item.CustomerName</td>
                                <td>@item.EmailAddress</td> 
                                <td>@item.TelephoneNumber</td>
                                @switch ((int)ViewBag.SelectedTypeId)
                                {
                                    case 1:                                            
                                        <td>
                                            @if (!string.IsNullOrEmpty(item.AttachPhotoLink))
                                            {
                                                foreach (var photo in item.AttachPhotoLink.Split(';'))
                                                {
                                                    <a target="_blank" href="/rdm/getfile?path=@photo">@photo.Split('\\').Last()</a>
                                                @*<img src="/rdm/getfile?path=@photo" style="width: 80px; height: 60px"/>*@
                                                }
                                            }
                                        </td>
                                        break;
                                    case 2:
                                        break;
                                    case 3:<td>@item.OrderStatus</td>
                                        break;
                                    case 4:<td>@item.ReasonToReturn</td><td>@item.ItemToReturn</td>
                                        break;
                                    case 5:<td>@item.ProductName</td>
                                        <td>@item.ReasonForCancellation</td>
                                        break;
                                    case 6 :<td>@item.SupplierIntroduction</td><td>@item.SupplierProductCategories</td><td>@item.SupplierContactName</td>
                                        break;
                                    case 7:<td>@item.AffiliateIntroduction</td><td>@item.AffiliateProductCategories</td><td>@item.AffiliateContactName</td>
                                        break;
                                }
                                <td>@item.DateApproved</td>
                                <td>@(item.User!=null?item.User.Username:"")</td>
                                <td>
                                    @if (item.TypeId == 1)
                                    {
                                        var action = ((List<tblKRMRSDisputeAction>)ViewBag.LstAction).FirstOrDefault(p => p.ActionID == item.ActionId);
                                        if (action != null)
                                        {
                                            <span>@action.Action</span>
                                        }
                                    }
                                    else
                                    {
                                        var action = ((List<tblCustomerHelpRequestAction>)ViewBag.LstAction).FirstOrDefault(p => p.Id == item.ActionId);
                                        if (action != null)
                                        {
                                            <span>@action.Name</span>
                                        }
                                    }
                                        
                                </td>
                                <td>@item.ReasonApprove</td>
                            </tr>
                        }
                    </tbody>
                }
            </table>

        </div>
    </div>
</div>
